// pages/plugins/exam/details/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 考试id
    id: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      id: options.id || null
    });
    options.pageName && (wx.setNavigationBarTitle({
      title: options.pageName,
    }))
    this.loadExamPaper();
  },

  // 获取考试题目
  loadExamPaper() {
    var that = this;
    var params = {
      point_url: app.server.agentApi.geApplicationGoodsDetails,
      id: that.data.id
    }
    app.server.getConnect(params).then(function(res) {
      that.setData(res.data);
    })
  },

  // 提交答卷
  formSubmit(e) {
    var that = this;
    var params = {
      point_url: app.server.agentApi.submitApplicationGoods,
      id: this.data.id,
      formId: this.data.formId,
      formData: e.detail
    }
    app.server.getConnect(params).then(function(res) {
      wx.redirectTo({
        url: '/pages/agent/plugins/applicationGoods/result/index?text=' + that.data.endLanguage,
      })
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    app.pageOnloadInit(this, app);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  onReachBottom: function() {
    // this.loadExamPaper();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    app.pageOnloadInit(this, app);
    wx.stopPullDownRefresh();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})